<?php
// **********************************************
// | Name: 星空框架  佳品源&惠工宝 对接
// **********************************************
// | Version: V1.0
// **********************************************
// | Author: xkyinzhe <zhonghuaxinxing@sina.cn>
// **********************************************
// | City: 青岛
// **********************************************
// | Time: 2023-11-28
// **********************************************
declare(strict_types=1);

namespace app\common\controller;

use think\facade\Db;
use app\common\common\BaseController;
use app\common\model\User as UserModel;
use app\common\services\UserServices;
use app\common\model\Withdrawal as WithDrawalModel;

/**
 * @xk 惠工宝处理
 */
class Huigongbao extends BaseController
{
  /**
   * @xk 回调信息中间件
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-28
   * @return void
   */
  public function syncBackAll()
  {
    $path = 'huigongbao/syncBackAll/';
    $param = request()->param();
    $method = isset($param['method']) ? $param['method'] : '';
    $data = isset($param['data']) ? $param['data'] : '';
    $result_data = [];
    if ($data) {
      $result_data = self::Decrypt($data);
    }
    $content = "接收原始数据：" . json_encode($param) . "/n";
    $content = "解密后数据：" . json_encode($result_data) . "/n";
    switch ($method) {
      case 'callback.merchant.employee.sign':
        // 身份认证回调处理
        $res = self::createBack($result_data);
        break;
      case 'callback.statement.payment.result.handle':
        $res = self::backInfo($result_data);
        break;
      default:
        $res = 'ok';
        break;
    }
    if ($res == 'ok') {
      echo 'SUCCESS';
      createLog($path, $content);
      exit();
    }
  }
  /**
   * @xk 获取用户信息
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-25
   * @param string $card_num
   * @return void
   */
  public static function getInfo($card_num = '')
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/employee/getDetail';
    $sign = self::Encrypt(['idCard' => $card_num]);
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = $sign;
    $body['sign'] = self::getSign($sign, $timestamp);
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      switch ($result['code']) {
        case '-1':
          throw new \think\Exception('【惠工宝】' . $result['message'], 300);
          break;
        case '-888':
          throw new \think\Exception('【惠工宝】' . "token错误", 404);
          break;
      }
    }
    $data = $result['data'];
    $result_data = self::Decrypt($data);
    return json_decode($result_data, true);
  }
  /**
   * @xk 获取银行卡号
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-27
   * @param string $card_num
   * @return void
   */
  public static function getBankNum($card_num = '')
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/employee/getDetail';
    $sign = self::Encrypt(['idCard' => $card_num]);
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = $sign;
    $body['sign'] = self::getSign($sign, $timestamp);
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      switch ($result['code']) {
        case '-1':
          throw new \think\Exception('【惠工宝】' . $result['message'], 300);
          break;
        case '-888':
          throw new \think\Exception('【惠工宝】' . "token错误", 404);
          break;
      }
    }
    $data = $result['data'];
    $result_data = self::Decrypt($data);
    $result_data = json_decode($result_data, true);
    $account_list = $result_data['paymentInfoResultList'];
    return isset($account_list[count($account_list) - 1]) ? $account_list[count($account_list) - 1]['account'] : '';
  }
  /**
   * @xk 获取银行卡信息
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-27
   * @param string $card_num
   * @return void
   */
  public static function getBankInfo($card_num = '')
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/employee/getDetail';
    $sign = self::Encrypt(['idCard' => $card_num]);
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = $sign;
    $body['sign'] = self::getSign($sign, $timestamp);
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      switch ($result['code']) {
        case '-1':
          throw new \think\Exception('【惠工宝】' . $result['message'], 300);
          break;
        case '-888':
          throw new \think\Exception('【惠工宝】' . "token错误", 404);
          break;
      }
    }
    $data = $result['data'];
    $result_data = self::Decrypt($data);
    $result_data = json_decode($result_data, true);
    $account_list = $result_data['paymentInfoResultList'];
    $bank_info = isset($account_list[count($account_list) - 1]) ? $account_list[count($account_list) - 1] : [];
    $bank_info['name'] = $result_data['name'];
    $bank_info['phone'] = $result_data['phone'];
    return $bank_info;
  }
  /**
   * @xk 校验用户是否完成签约
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-27
   * @param string $card_num
   * @return void
   */
  public static function checkCardNum($card_num = '')
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/employee/exist';
    $sign = self::Encrypt(['idCard' => $card_num]);
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = $sign;
    $body['sign'] = self::getSign($sign, $timestamp);
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      switch ($result['code']) {
        case '-1':
          throw new \think\Exception($result['message'], 300);
          break;
        case '-888':
          throw new \think\Exception("token错误", 404);
          break;
        default:
          throw new \think\Exception("异常错误" . $result['message'], 400);
          break;
      }
    }
    $data = $result['data'];
    $result_data = self::Decrypt($data);
    $result_data = json_decode($result_data, true);
    return $result_data['result'] ? 1 : 0;
  }
  /**
   * @xk 更换员工银行卡
   *
   * @method chanageBank
   * @param  [type]      $data                      [description]
   * @return [type]      [description]
   * @Time   2021-12-02
   * @City   青岛
   * @Author xkyinzhe    <zhonghuaxinxing@sina.cn>
   */
  public static function chanageBank($data = [])
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/employee/addAccount';
    $sign = self::Encrypt($data);
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = $sign;
    $body['sign'] = self::getSign($sign, $timestamp);
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      switch ($result['code']) {
        case '-1':
          throw new \think\Exception('【惠工宝】' . $result['message'], 300);
          break;
        case '-888':
          throw new \think\Exception("token错误", 404);
          break;
      }
    }
    return true;
  }
  /**
   * @xk 提交打款信息给惠工宝
   *
   * @method syncOrder
   * @param  [type]     $data                      [description]
   * @return [type]     [description]
   * @Time   2021-11-26
   * @City   青岛
   * @Author xkyinzhe   <zhonghuaxinxing@sina.cn>
   */
  public static function syncOrder($data)
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $data['projectCode'] = config('web_config.organizationName');
    $data['paymentChannelType'] = 10;
    $data['paymentType'] = 1;
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/statement/saveStatementImport';
    $path = 'huigongbao/syncOrder/';
    $info = json_encode($data);
    createLog($path, $info);
    $sign = self::Encrypt($data);
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = $sign;
    $body['sign'] = self::getSign($sign, $timestamp);
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      throw new \think\Exception('【惠工宝】' . $result['message'], 404);
    }
    $data = $result['data'];
    $result_data = self::Decrypt($data);
    createLog($path, $result_data);
    $result_data = json_decode($result_data, true);
    if(!$result_data['result']){
      throw new \think\Exception('【惠工宝】返回错误信息，提交数据异常，被驳回'.$result_data['errorList'][0]['name'].'因为'.$result_data['errorList'][0]['errorReason'], 404);
    }
    return true;
  }
  /**
   * @xk 拒绝审核处理
   *
   * @method checkNoOrder
   * @param  [type]       $currentId                 [description]
   * @return [type]       [description]
   * @Time   2021-12-06
   * @City   青岛
   * @Author xkyinzhe     <zhonghuaxinxing@sina.cn>
   */
  public static function checkNoOrder($customizableOrderId = '')
  {
    $withDrawalModel = new WithDrawalModel();
    $userServices = new UserServices();
    Db::startTrans();
    $info = '';
    try {
      $list = $withDrawalModel
        ->where([['withdrawal_sn', '=', $customizableOrderId]])
        ->field('`with_drawal_id`,`status`,`withdrawal_sn`')
        ->select();
      $list = $list ? $list->toArray() : [];
      foreach ($list as $key => $value) {
        if ($value['status'] != 1) {
          $content = $value['withdrawal_sn'] . '当前状态不允许此接口调整';
          createLog('huigongbao/checkNoOrder/', $content);
          continue;
        }
        $push_data = [];
        $push_data['next_check_time'] = date('Y-m-d H:i:s');
        $push_data['over_time'] = date('Y-m-d H:i:s');
        $push_data['status'] = 4;
        $withDrawalModel->where([['with_drawal_id', '=', $value['with_drawal_id']]])->save($push_data);
        $userServices->syncBackWithDrawal((string) $value['with_drawal_id'], 4);
      }
      $info .= $customizableOrderId . "三方拒绝审核处理";
      Db::commit();
    } catch (\Exception $e) {
      Db::rollback();
      $info .= $e->getMessage();
    }
    $path = 'huigongbao/checkNoOrder/';
    createLog($path, $info);
  }
  /**
   * @xk 查询派单批次处理结果
   *
   * @method queryOrder
   * @return [type]     [description]
   * @Time   2021-12-06
   * @City   青岛
   * @Author xkyinzhe   <zhonghuaxinxing@sina.cn>
   */
  public static function queryOrder($customizableOrderId = '')
  {
    $withDrawalModel = new WithDrawalModel();
    $userServices = new UserServices();
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/statementDetail/searchApiStatementDetail';
    $list = $withDrawalModel
            ->where([['withdrawal_sn', '=', $customizableOrderId]])
            ->field('`with_drawal_id`,`status`,`withdrawal_sn`')
            ->select()
            ->toArray();
    if ($list) {
      foreach ($list as $key => $value) {
        if ($value['status'] != 1) {
          $content = $value['withdrawal_sn'] . '当前状态不允许此接口调整';
          createLog('huigongbao/orderError/', $content);
          continue;
        }
        $customizableOrderIdList = [];
        $customizableOrderIdList['customizableOrderIdList'] = $value['withdrawal_sn'];
        $sign = self::Encrypt($customizableOrderIdList);
        $body = [];
        $timestamp = time();
        $body['timestamp'] = $timestamp;
        $body['data'] = $sign;
        $body['sign'] = self::getSign($sign, $timestamp);
        $res = self::https_request($url, json_encode($body), $header);
        $result = json_decode($res, true);
        if ($result['code'] != 0) {
          $content = $result['message'];
          createLog('huigongbao/orderError/', $content);
          continue;
        }
        $data = $result['data'];
        $result_data = self::Decrypt($data);
        $result_data = json_decode($result_data, true);
        $list = isset($result_data[0]) ? $result_data[0] : [];
        $status = $list['status'];
        $push_data = [];
        $push_data['next_check_time'] = date('Y-m-d H:i:s');
        $push_data['over_time'] = date('Y-m-d H:i:s');
        switch ($status) {
          case '20':
            $push_data['status'] = 3;
            $withDrawalModel->where([['withdrawal_sn', '=', $value['withdrawal_sn']]])->save($push_data);
            $userServices->syncPushSuccess($value['withdrawal_sn']); // 记录提现成功
            break;
          case '30':
            $push_data['status'] = 4;
            $userServices->syncBackWithDrawal((string) $value['with_drawal_id'], 4);
            break;
        }
        createLog('huigongbao/orderSuccess/', $value['withdrawal_sn'] . "处理成功\n");
      }
    }
  }
  // +------------
  // | 相关回调数据
  // +--------------
  /**
   * @xk 实名认证回调
   *
   * @method createBack
   * @return [type]     [description]
   * @Time   2021-12-02
   * @City   青岛
   * @Author xkyinzhe   <zhonghuaxinxing@sina.cn>
   */
  public static function createBack($param = [])
  {
    Db::startTrans();
    $userModel = new UserModel();
    $path = 'huigongbao/createBack/';
    $content = json_encode($param) . "/n";
    createLog($path, $content);
    try {
      $user_sn = isset($param['remark']) ? $param['remark'] : '';
      $card_num = isset($param['idCard']) ? $param['idCard'] : '';
      $is_check = isset($param['state']) ? $param['state'] == 1 ? 1 : 0 : 0;
      if ($user_sn == '') {
        throw new \think\Exception("用户信息不存在", 404);
      }
      if ($card_num == '') {
        throw new \think\Exception("用户身份信息失效", 404);
      }
      $userModel->where([['user_sn', '=', $user_sn]])->save(['card_num' => $card_num, 'is_check' => $is_check]);
      $content = '【' . $user_sn . '】数据回调认证成功';
      Db::commit();
      return "ok";
    } catch (\Exception $e) {
      Db::rollback();
      $content = $e->getMessage();
    }
    createLog($path, $content);
  }
  /**
   * @xk 返回节点
   *
   * @method backInfo
   * @return [type]     [description]
   * @Time   2021-11-26
   * @City   青岛
   * @Author xkyinzhe   <zhonghuaxinxing@sina.cn>
   */
  public static function backInfo($param = [])
  {
    $info = json_encode($param);
    $paymentResult = isset($param['paymentResult']) ? $param['paymentResult'] : '';
    $customizableOrderId = isset($param['customizableOrderId']) ? $param['customizableOrderId'] : '';
    switch ($paymentResult) {
      case 'SUCCESS':
        self::queryOrder($customizableOrderId);
        break;
      case 'FAIL':
        if ($customizableOrderId) {
          self::checkNoOrder($customizableOrderId);
        }
        break;
    }
    $path = 'huigongbao/backInfo/';
    createLog($path, $info);
    return "ok";
  }

  /**
   * @xk 获取token接口
   *
   * @method getToken
   * @return [type]     [description]
   * @Time   2021-10-21
   * @City   青岛
   * @Author xkyinzhe   <zhonghuaxinxing@sina.cn>
   */
  public static function getToken()
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $hg_appscript = config('core_config.huigongbao_new_config.hg_appscript');
    $header = [
      "appId: " . $hg_appid,
      "token: ",
      "Content-type: application/json"
    ];
    $data = [];
    $data['appId'] = $hg_appid;
    $data['appSecret'] = $hg_appscript;
    $sign = self::Encrypt($data);
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = $sign;
    $body['sign'] = self::getSign($sign, $timestamp);
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/api/getToken';
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result) {
      if ($result['code'] != 0) {
        switch ($result['code']) {
          case '-1':
            throw new \think\Exception($result['message'], 300);
            break;
          case '-888':
            throw new \think\Exception("token错误", 404);
            break;
        }
      }
      $result_data = self::Decrypt($result['data']);
      $result_data = json_decode($result_data, true);
      return $result_data['token'];
    } else {
      return '';
    }

  }
  /**
   * @xk 执行RSA加密
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-25
   * @param array $data
   * @return void
   */
  public static function Encrypt($data = [])
  {
    $hg_public_key = msubstr(config('core_config.huigongbao_new_config.hg_public_key'), 0, 150000);
    $rsa_publickey = "-----BEGIN PUBLIC KEY-----\n" .
      wordwrap($hg_public_key, 64, "\n", true) .
      "\n-----END PUBLIC KEY-----";
    ($rsa_publickey) or die('公钥格式错误');
    $data = json_encode($data);
    $split = str_split($data, 117);  // 1024 bit && OPENSSL_PKCS1_PADDING  
    $sign = '';
    foreach ($split as $chunk) {
      $isOkay = openssl_public_encrypt($chunk, $encryptData, $rsa_publickey);
      if (!$isOkay) {
        return false;
      }
      $sign .= $encryptData;
    }
    return base64_encode($sign);
  }
  /**
   * @xk 执行RSA私钥解密
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-25
   * @param string $data
   * @return void
   */
  public static function Decrypt($data = '')
  {
    $hg_public_key = msubstr(config('core_config.huigongbao_new_config.hg_private_key'), 0, 150000);
    $pem = chunk_split($hg_public_key, 64, "\n");
    $rsa_privatekey = "-----BEGIN RSA PRIVATE KEY-----\n" . $pem . "-----END RSA PRIVATE KEY-----";
    $rsa_privatekey = openssl_pkey_get_private($rsa_privatekey);
    ($rsa_privatekey) or throw new \think\Exception("惠工宝私钥格式错误，请联系开发者查看", 400);
    ;
    $data = base64_decode($data);
    $split = str_split($data, 128);  // 1024 bit  固定172
    $crypto = '';
    foreach ($split as $chunk) {
      $decryptedChunk = '';
      if (!openssl_private_decrypt($chunk, $decryptedChunk, $rsa_privatekey)) {
        throw new \think\Exception("惠工宝数据解密失败", 400);
      }
      $crypto .= $decryptedChunk;
    }
    return json_decode($crypto, true);
  }

  /**
   * @xk 对所有参数执行MD5最终加密
   *
   * @Version: V1.0
   * @Author: xkyinzhe <zhonghuaxinxing@sina.cn>
   * @City: 青岛
   * @Time 2023-11-23
   * @param [type] $sign
   * @param [type] $timestamp
   * @return void
   */
  public static function getSign($sign, $timestamp)
  {
    $hg_appscript = config('core_config.huigongbao_new_config.hg_appscript');
    $new_str = $sign . $hg_appscript . $timestamp;
    return MD5($new_str);
  }

  /**
   * @xk curl访问
   *
   * @method https_request
   * @param  [type]        $url                       [description]
   * @param  [type]        $data                      [description]
   * @param  array         $headers                   [description]
   * @return [type]        [description]
   * @Time   2021-11-05
   * @City   青岛
   * @Author xkyinzhe      <zhonghuaxinxing@sina.cn>
   */
  public static function https_request($url, $data = [], $headers = ["Content-type: application/json;charset='utf-8'"], $type = 'post')
  {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    if ($type == 'post') {
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    if (!empty($data)) {
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);

    return $output;
  }
  // +-------------------
  // | 废弃接口  全部
  // +---------------------
  /**
   * @xk 创建实名认证  目前接口处于废弃状态
   *
   * @method createUser
   * @param  [type]     $data                      [description]
   * @return [type]     [description]
   * @Time   2021-11-10
   * @City   青岛
   * @Author xkyinzhe   <zhonghuaxinxing@sina.cn>
   */
  public static function createUser($data)
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $hg_appscript = config('core_config.huigongbao_new_config.hg_appscript');
    $token = self::getToken();
    $header = [
      "timestamp:" . time(),
      "token: " . $token,
      "Content-type: application/json;charset='utf-8'"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . 'java/api/bindEmployee';
    $post_data = [];
    $post_data[] = $data;
    $res = self::https_request($url, json_encode($post_data), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      switch ($result['code']) {
        case '-1':
          throw new \think\Exception('【惠工宝】' . $result['message'], 404);
          break;
        case '-888':
          throw new \think\Exception('【惠工宝】' . "token错误", 404);
          break;
      }
    }
    $data = $result['data'];
    if ($data['failed']) {
      throw new \think\Exception($data['failed'][0]['remark'], 404);
    }
    if ($data['success']) {
      return $data['success'][0]['idCard'];
    }
  }

  /**
   * @xk 接口不需要了  废弃
   *
   * @method getAllCompanyConfig
   * @return [type]              [description]
   * @Time   2021-11-26
   * @City   青岛
   * @Author xkyinzhe            <zhonghuaxinxing@sina.cn>
   */
  public static function getAllCompanyConfig()
  {
    $hg_appid = config('core_config.huigongbao_new_config.hg_appid');
    $token = self::getToken();
    $header = [
      "appId: " . $hg_appid,
      "token: " . $token,
      "Content-type: application/json"
    ];
    $url = config('core_config.huigongbao_new_config.hg_linkurl') . '/merchant-service/api/merchant/capital/getMerchantCapital';
    $body = [];
    $timestamp = time();
    $body['timestamp'] = $timestamp;
    $body['data'] = '';
    $body['sign'] = self::getSign('', $timestamp);
    $res = self::https_request($url, json_encode($body), $header);
    $result = json_decode($res, true);
    if ($result['code'] != 0) {
      switch ($result['code']) {
        case '-1':
          throw new \think\Exception($result['message'], 300);
          break;
        case '-888':
          throw new \think\Exception("token错误", 404);
          break;
      }
    }
    $data = $result['data'];
    $result_data = self::Decrypt($data);
    dump($result_data);
    die();
    $list = $result['data'];
    $organizationNameArr = array_column($list, 'organizationName');
    $array_key = array_search(config('web_config.organizationName'), $organizationNameArr);
    return $result['data'][$array_key];
  }

}
